python多变量拟合 您所在的位置:网站首页 Curve Fitting Fool python多变量拟合

python多变量拟合

#python多变量拟合| 来源: 网络整理| 查看: 265

Python's curve_fit calculates the best-fit parameters for a function with a single independent variable, but is there a way, using curve_fit or something else, to fit for a function with multiple independent variables? For example:

def func(x, y, a, b, c):

return log(a) + b*log(x) + c*log(y)

where x and y are the independent variable and we would like to fit for a, b, and c.

解决方案

You can pass curve_fit a multi-dimensional array for the independent variables, but then your func must accept the same thing. For example, calling this array X and unpacking it to x, y for clarity:

import numpy as np

from scipy.optimize import curve_fit

def func(X, a, b, c):

x,y = X

return np.log(a) + b*np.log(x) + c*np.log(y)

# some artificially noisy data to fit

x = np.linspace(0.1,1.1,101)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有